package com.hongdee.crm.task.vw.service.impl;

import com.hongdee.annotation.MethodComment;
import com.hongdee.common.util.DateUtils;
import com.hongdee.crm.Constant;
import com.hongdee.crm.maintain.entity.TCrmCarMaintain;
import com.hongdee.crm.task.vw.dao.ITCrmVwTaskDao;
import com.hongdee.crm.task.vw.service.ITCrmVwTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 名  称: TCrmVwTaskServiceImpl
 * 类  型: class
 * 描  述: 大众相关任务处理
 * 路  径: com.hongdee.crm.task.vw.service.impl
 * 作  者: wangshuai
 * 日  期: 2017-04-20
 */
@Service
public class TCrmVwTaskServiceImpl implements ITCrmVwTaskService {

    @Autowired
    private ITCrmVwTaskDao vwTaskDao;

    private final int LIMIT = 1000;

    /**
     * 更新车辆品牌 车系
     *
     * @param companyId
     * @throws Exception
     */
    @Override
    @MethodComment(name = "更新大众车辆品牌、车系信息")
    public Integer updDzBrandQuartz(String companyId) throws Exception {
        Integer nums = 0;
        String sql = "update t_crm_car car, " +
                "(select * from t_crm_car_workorder where company_id=? GROUP BY vin) worder " +
                "set car.brand=worder.brand,car.series=worder.series,car.configure=worder.model " +
                "where car.vin=worder.vin and car.company_id=worder.company_id and car.company_id=?";
        nums += this.vwTaskDao.executeSQL(sql, companyId, companyId);

        String sqlQT = "update t_crm_car car set  car.series='QT'  where car.series='QITA' and car.company_id= ?";

        nums += this.vwTaskDao.executeSQL(sqlQT, companyId);
        //山东润捷车型
        sqlQT = "update t_crm_car car set  car.series='QT'  where car.series='其它' ";
        nums += this.vwTaskDao.executeSQL(sqlQT);
        //刷新无车系车型车辆
        sqlQT = "update t_crm_car car set  car.series=''  where car.series is null ";
        nums += this.vwTaskDao.executeSQL(sqlQT);

        return nums;
    }

    /**
     * 根据分配的VIN信息，更新任务处理人
     *
     * @throws Exception
     */
    @Override
    @MethodComment(name = "根据分配的VIN账号，更新任务处理人")
    public void updDzTaskSaIdQuartz() throws Exception {
        String sql = "UPDATE t_crm_task_real task,t_crm_car_ref_detail detail " +
                "SET task.sa_id=detail.uid " +
                "where task.company_id=detail.company_id and task.vin=detail.vin ";
        this.vwTaskDao.executeSQL(sql);
    }

    @Override
    @MethodComment(name = "更新车辆所属人员ID")
    public void updRefDetailUidQuartz() throws Exception {
        String sql = "UPDATE t_crm_car_ref_detail detail,t_bc_user bcUser " +
                "set detail.uid=bcUser.id " +
                "where detail.u_name=bcUser.u_name";
        this.vwTaskDao.executeSQL(sql);
    }


}

